<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>待确认订单列表</title>
</head>
<style>
    .table > tbody > tr > td {
        text-align: center;
    }
</style>
<body>

<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span
            class="c-gray en">&gt;</span> 待确认订单列表 <a class="btn btn-success radius r"
                                                  style="line-height:1.6em;margin-top:3px"
                                                  href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l"><a href="javascript:;" onclick="batchComfirm()" class="btn btn-primary radius"><i
        class="Hui-iconfont">&#xe6a7;</i> 批量确认</a></span>
        <span class="l"><a href="javascript:;" onclick="orderAdd()" class="btn btn-success radius"><i
        class="Hui-iconfont">&#xe600;</i> 新增订单</a></span>
        </div>
            <div class="panel panel-default  mt-20">
                <div class="panel-header">时间筛选</div>
                <div class="panel-body">
                    <div class="skin-minimal" id="time-selector">
                        <div class="check-box">
                            <input type="radio" name="time" value="0">
                            <label>所有</label>
                        </div>
                        <div class="check-box">
                            <input type="radio" name="time" value="1" checked>
                            <label>当天</label>
                        </div>
                    </div>
                </div>
            </div>
        <div class="mt-20">
            <div class="mt-20" style="margin-bottom: 70px">
                <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="80">订单号</th>
                        <th width="80">患者姓名</th>
                        <th width="80">联系电话</th>
                        <th width="100">物品清单</th>
                        <th width="60">下单时间</th>
                        <th width="60">预约时间</th>
                        <th width="80">配送地址</th>
                        <th width="100">医保</th>
                        <th width="100">医保类型</th>
                        <th width="100">付款方式</th>
                        <th width="100">备注</th>
                        <th width="100">下单人</th>
                        <th width="100">订单状态</th>
                        <th width="50">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/common.js"></script>

<script type="text/javascript" src="lib/LodopFuncs.js"></script>
<script type="text/javascript" src="lib/printer.js"></script>

<script type="text/javascript">


    var start = getTodayStart()
    var end = getTodayEnd()
    for (var i = 1;i<5;i++){
        var t = Date.parse(getTodayStart().replace(/-/g, "/"))
        t = t + i*24*60*60*1000
        $('#time-selector').append("<div class=\"check-box\"><input type=\"radio\" name=\"time\" value="+(parseInt(i)+1)+" ><label>"+dateymd(t)+"</label></div>")
    }

    $('input[name=state],input[name=time]').change(function (e) {

        radioValue = $('input[name=time]:checked').val()
        switch (radioValue) {
            case '1':
                start = getTodayStart()
                end = getTodayEnd()
                break
            case '0':
                start = ""
                end = ""
                break;
            default :
                console.log(radioValue)
                var t = Date.parse(getTodayStart().replace(/-/g, "/"))
                t = t + (radioValue-1)*24*60*60*1000
                start = dateAll(t)
                var e = Date.parse(getTodayEnd().replace(/-/g, "/"))
                e = e + (radioValue-1)*24*60*60*1000
                end = dateAll(e)
                break;
        }

        table.destroy()
        table =   $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url: "./order/uncomfired/list",
                type: 'GET',
                data: {
                    "searchKey": "",
                    "minDate": start,
                    "maxDate":end,
                    "state":"0"
                }
            },
            "columns": [
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
                    }
                },
                {"data": "orderId"},

                {
                    "data": "receiverName"
                },
                {
                    "data": "receiverPhone"
                },
                {
                    "data": "medicineList",
                    render: function (data, type, row, meta) {
                        var s = ""
                        for (var i = 0;i<data.length;i++){

                            var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
                            s += a;
                        }
                        return s
                    }
                },
                {
                    "data": "createTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "reserveTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "receiverAddress"
                },
                {
                    "data": "insurance"
                },
                {
                    "data": "insuranceType"
                },
                {
                    "data": "paymentType"
                },
                {
                    "data": "prescriptionPic"
                },
                {
                    "data": "memberName"
                },
                {
                    "data": "status",
                    render: function (data, type, row, meta) {
                        if (data == -1) {
                            return "<span class=\"label label-defant radius td-status\">已取消</span>";
                        } else
                        if (data == 0) {
                            return "<span class=\"label label-defant radius td-status\">待确认</span>";
                        } else if (data == 10) {
                            return "<span class=\"label label-warning radius td-status\">已确认</span>";
                        } else if (data == 20) {
                            return "<span class=\"label label-primary radius td-status\">已配药</span>";
                        } else if (data == 30) {
                            return "<span class=\"label label-secondary radius td-status\">已分配派送员</span>";
                        }else if (data == 35) {
                            return "<span class=\"label label-secondary radius td-status\">配送中</span>";
                        } else if (data == 40) {
                            return "<span class=\"label label-success radius td-status\">已完成</span>";
                        } else if (data == -10) {
                            return "<span class=\"label label-danger radius td-status\">订单取消</span>";
                        } else {
                            return "<span class=\"label label-warning radius td-status\">其它态</span>";
                        }
                    }
                },
                {
                    "data": null,
                    render: function (data, type, row, meta) {

                        return '<button class="btn btn-primary radius" style="margin-bottom: 10px;" type="button" onclick="comfire(' + row.orderId + ','+meta.row+')">确认订单</button>' +
                            '<button class="btn btn-secondary radius" style="margin-bottom: 10px;" type="button" onclick="edit(' + row.orderId + ','+meta.row+')">编辑订单</button>' +
                            '<button class="btn btn-danger radius" type="button" onclick="cancel(\'' + row.orderId + '\')">取消订单</button>';
                    }
                }
            ],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable": false, "aTargets": [0,4]}// 制定列不参与排序
            ],
            language: {
                url: './lib/datatables/Chinese.json'
            },
            colReorder: true
        });

    })



    /*datatables配置*/
     var table =   $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url: "./order/uncomfired/list",
                type: 'GET',
                data: {
                    "searchKey": "",
                    "minDate": start,
                    "maxDate": end,
                    "state":"0"
                }
            },
            "columns": [
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
                    }
                },
                {"data": "orderId"},
                {"data": "receiverName"},
                {
                    "data": "receiverPhone"
                },
                {
                    "data": "medicineList",
                    render: function (data, type, row, meta) {
                        var s = ""
                        for (var i = 0;i<data.length;i++){

                            var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
                            s += a;
                        }
                        return s
                    }
                },
                {
                    "data": "createTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "reserveTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "receiverAddress"
                },
                {
                    "data": "insurance"
                },
                {
                    "data": "insuranceType"
                },
                {
                    "data": "paymentType"
                },
                {
                    "data": "prescriptionPic"
                },
                {
                    "data": "memberName"
                },
                {
                    "data": "status",
                    render: function (data, type, row, meta) {
                        if (data == -1) {
                            return "<span class=\"label label-defant radius td-status\">已取消</span>";
                        } else
                        if (data == 0) {
                            return "<span class=\"label label-defant radius td-status\">待确认</span>";
                        } else if (data == 10) {
                            return "<span class=\"label label-warning radius td-status\">已联系</span>";
                        } else if (data == 20) {
                            return "<span class=\"label label-primary radius td-status\">已配药</span>";
                        } else if (data == 30) {
                            return "<span class=\"label label-secondary radius td-status\">已分配派送员</span>";
                        } else if (data == 40) {
                            return "<span class=\"label label-success radius td-status\">已完成</span>";
                        } else if (data == -10) {
                            return "<span class=\"label label-danger radius td-status\">订单取消</span>";
                        } else {
                            return "<span class=\"label label-warning radius td-status\">其它态</span>";
                        }
                    }
                },
                {
                    "data": null,
                    render: function (data, type, row, meta) {

                        return '<button class="btn btn-primary radius" style="margin-bottom: 10px;" type="button" onclick="comfire(' + row.orderId + ','+meta.row+')">确认订单</button>' +
                            '<button class="btn btn-secondary radius" style="margin-bottom: 10px;" type="button" onclick="edit(' + row.orderId + ','+meta.row+')">编辑订单</button>' +
                            '<button class="btn btn-danger radius" type="button" onclick="cancel(\'' + row.orderId + '\')">取消订单</button>';
                    }
                }
            ],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable": false, "aTargets": [0,4]}// 制定列不参与排序
            ],
            language: {
                url: './lib/datatables/Chinese.json'
            },
            colReorder: true
        });



    /*批量确认*/
    function batchComfirm() {
        var cks = document.getElementsByName("checkbox");
        var count = 0, ids = "",rowdatas=[]
        for (var i = 0; i < cks.length; i++) {
            if (cks[i].checked) {
                count++;
                ids += cks[i].value + ",";
                var rowdata = table.row(i).data()
                rowdatas.push(rowdata)
            }
        }
        if (count == 0) {
            layer.msg('您还未勾选任何数据!', {icon: 5, time: 3000});
            return;
        }
        /*去除末尾逗号*/
        if (ids.length > 0) {
            ids = ids.substring(0, ids.length - 1);
        }
        layer.confirm('确认要确认所选的' + count + '条数据吗？', {icon: 0}, function (index) {
            var index = layer.load(3);
            $.ajax({
                type: 'POST',
                url: './order/' + ids+'/cc',
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.success != true) {
                        layer.alert(data.message, {title: '错误信息', icon: 2});
                        return;
                    }
                    layer.msg('已确认!', {icon: 1, time: 1000});

                    refresh();

                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                }
            });
        });
    }

    function comfire(orderId,index) {
        var rowdata = table.row(index).data()
        layer.confirm('要确认该订单吗？', {icon: 0}, function (index) {
            var index = layer.load(3);
            $.ajax({
                type: 'post',
                url: './order/' + orderId + '/cc',
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.success != true) {
                        layer.alert(data.message, {title: '错误信息', icon: 2});
                        return;
                    }
                    layer.msg('设置成功!', {icon: 1, time: 1000});
                    refresh();
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                }
            });
        });
    }

    function cancel(orderId) {
        layer.confirm('<div><div>输入取消订单原因</div><textarea class="textarea" id="content"></textarea></div>', {}, function (index) {
            var index = layer.load(3);
            var content = $("#content").val()
            $.ajax({
                type: 'post',
                url: './order/' + orderId + '/cancel',
                data:{
                    content:content
                },
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.success != true) {
                        layer.alert(data.message, {title: '错误信息', icon: 2});
                        return;
                    }
                    layer.msg('取消成功!', {icon: 1, time: 1000});
                    // orderCount();
                    refresh();
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                }
            });
        });
    }
    
    var order = {}

    function edit(orderId,index) {
        var rowdata = table.row(index).data()
        order = {
            orderId:rowdata.orderId,
            receiverName:rowdata.receiverName,
            receiverPhone:rowdata.receiverPhone,
            receiverAddress:rowdata.receiverAddress,
            addressType:rowdata.addressType,
            reserveTime:rowdata.reserveTime,
            paymentType:rowdata.paymentType,
            insuranceType:rowdata.insuranceType,
            insurance:rowdata.insurance,
            receiverState:rowdata.receiverState,
            receiverCity:rowdata.receiverCity,
            receiverDistrict:rowdata.receiverDistrict,
            medicineList:rowdata.medicineList,
            prescriptionPic:rowdata.prescriptionPic
        }
        layer_show("编辑订单", "order-edit");
    }

    function orderAdd() {
        layer_show("新增订单", "order-add");

    }

    function msgSuccess(content) {
        layer.msg(content, {icon: 1, time: 3000});
    }
</script>
</body>
</html>